/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Category;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author MrChinh
 */
public class ListCategory {
    ConnectDB myConn = new ConnectDB();
    Connection conn;
    
    public List<Category> getListCategory(){
        List<Category> listC = new ArrayList<Category>();
        try {
            conn = myConn.getConnect();
            Statement stmt  = conn.createStatement();
            String sql = "SELECT * FROM Category";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                Category cate = new Category();
                cate.setCategoryId(rs.getString(1));
                cate.setCategoryName(rs.getString(2));
                cate.setDescription(rs.getString(3));
                listC.add(cate);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listC;
    }
}
